<template>
	<view>
		
	<my-search @myclick="goSearch"></my-search>
	
		
		<view class="scroll-container">
			<!-- 左侧的滑动区域 -->
			<scroll-view class="left-scroll" scroll-y="true" :style="{height:wh+'px'}">
				<block v-for="(item,i) in cateList" :key="i">
				<view :class="['left-scroll-item',i===active ? 'active':'']" @click="activeChanged(i)">{{item.cat_name}}</view>
				</block>
			</scroll-view>
			<!-- 右侧的滑动区域 -->
			<scroll-view class="right-scroll" scroll-y="true" :style="{height:wh +'px'}" :scroll-top="scroolTop">
				<view class="right-scroll-item" v-for="(item2,i2) in cateListTwo" :key="i2">
	         	<view class="right-scroll-title">/ {{item2.cat_name}} /</view>			
						<!-- 动态渲染三级分类列表数据 -->
						<view class="right-scroll-list">
							<!-- 三级分类item项 -->
							<view class="right-scroll-list-three" v-for="(item3,i3) in item2.children" :key="i3" 
							@click="goGoodsList(item3)">
							<!-- 三级图片部分	 -->
							<image :src="item3.cat_icon" ></image>
							<!-- 三级描述部分 -->
							<text>{{item3.cat_name}}</text>
							</view>
						</view>
				</view>
				</scroll-view>
		</view>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabber-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				// 当前设备可以的高度
				wh:0,
				// 商品列表数据
				cateList:[],
				// 商品列表二级数据
				cateListTwo:[],
				// 默认的激活项
				active:0,
				// 点击项重新回到顶部,代表距离顶部的距离
				scroolTop:0
			};
		},
		onLoad() {
			// 获取设备的宽高等配置信息
		const sysInfo =	uni.getSystemInfoSync()
		// console.log('sdad',sysInfo)
		this.wh=sysInfo.windowHeight-50
		
		
		},
		onShow(){
				this.getCateList()
		},
		methods: {
			// 获取分类列表的数据
		async	getCateList() {
			const {data:res} =await uni.$http.get('/api/public/v1/categories')
				// console.log('aaaa',res)
				if(res.meta.status!==200) return uni.$showMsg()
				this.cateList=res.message
				
				// 为二级分类赋值
			this.cateListTwo=	res.message[i].children
			},
			// 点击高亮
			activeChanged(i){
				this.active=i
				
				// 重新为二级分类赋值/监听id
	  	this.cateListTwo=	this.cateList[i].children
    	this.scroolTop=this.scroolTop===0 ? 1:0
			},
			
			// 跳转到商品列表页面
			goGoodsList(item){
				uni.navigateTo({
					url:'/subpkg/goods_list/goods_list?cid='+item.cat_id
				})
			},
			// 搜索触发的事件
			goSearch(){
				// console.log('ok')
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		},
	}
</script>

<style lang="scss">

.scroll-container{
	display: flex;
}
.left-scroll{
	width: 120px;
	height: 100vh;
}
.left-scroll-item{
	background-color: #f7f7f7;
	line-height: 60px;
	text-align: center;
	font-size: 12px;
	
	&.active{
		background-color: #ffffff;
		position: relative;
		&::before{
			content: '';
			display: block;
      width: 3px;
			height: 30px;
			background-color: red;
			position: absolute;
			top: 50%;
			left: 0;
			transform: translateY(-50%)
		}
	}
}
.right-scroll{
	background-color: #ffffff;
}
.right-scroll-title{
	text-align: center;
	padding: 15px 0 5px 0;
	font-size: 13px;
	font-weight: bold;
}
.right-scroll-list{
	display: flex;
	flex-wrap: wrap;
	.right-scroll-list-three{
		width: 33.33%;
		display: flex;
		flex-direction: column;//纵向布局
		justify-content: center;//纵向居中
		text-align: center;
		margin-bottom: 10px;
		image{
			width: 60px;
	   	height: 60px;
			margin: 2rpx auto;
		}
		text{
			font-size: 12px;
		}
	}
}
</style>
